# Contributor: Natanael Copa <ncopa@alpinelinux.org>
# Maintainer: Natanael Copa <ncopa@alpinelinux.org>
pkgname=snappy
pkgver=1.1.8
pkgrel=2
pkgdesc="Fast compression and decompression library"
url="https://google.github.io/snappy/"
arch="all"
license="BSD-3-Clause"
makedepends="cmake"
subpackages="$pkgname-dbg $pkgname-static $pkgname-dev $pkgname-doc"
source="$pkgname-$pkgver.tar.gz::https://github.com/google/snappy/archive/$pkgver.tar.gz
	optimize-mips-s390x.patch
	cmakelists.patch
	"

build() {
	if [ "$CBUILD" != "$CHOST" ]; then
		CMAKE_CROSSOPTS="-DCMAKE_SYSTEM_NAME=Linux -DCMAKE_HOST_SYSTEM_NAME=Linux"
	fi
	cmake \
		-DCMAKE_BUILD_TYPE=None \
		-DCMAKE_INSTALL_PREFIX=/usr \
		-DCMAKE_INSTALL_LIBDIR=/usr/lib \
		-DBUILD_SHARED_LIBS=ON \
		-DBUILD_STATIC_LIBS=ON \
		-DCMAKE_CXX_FLAGS="$CXXFLAGS" \
		-DCMAKE_C_FLAGS="$CFLAGS" \
		${CMAKE_CROSSOPTS} .
	cmake --build .
}

check() {
	ctest --verbose
}

package() {
	make DESTDIR="$pkgdir" install

	local file; for file in AUTHORS CONTRIBUTING.md COPYING NEWS README.md \
		format_description.txt framing_format.txt; do
		install -m644 -D $file "$pkgdir"/usr/share/doc/$pkgname/$file
	done
}

sha512sums="efe18ff1b3edda1b4b6cefcbc6da8119c05d63afdbf7a784f3490353c74dced76baed7b5f1aa34b99899729192b9d657c33c76de4b507a51553fa8001ae75c1c  snappy-1.1.8.tar.gz
a14b0159631beac628cf99cf9ad970631dfdbf607ca2c3911a64124d1133694689dc76a70f25d4f780ce7093584249905aec2926ef7a3d9350952f7648938392  optimize-mips-s390x.patch
6a379a1bd026282d98d5f2ffd316e126d5383b7c32852f81102c7a2aa0754e0c5567f82766dbd72b62552ef8a9569795c5f667387d3f1b2c9ef2bfffc578de18  cmakelists.patch"
